package com.example.demo.streamstudy;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Description StreamTest2
 * @Author songchuanlong
 * @Date 2025-05-21
 */
public class StreamTest2 {
    public static void main(String[] args) {
        //1.如何获取List集合的Stream流
        List<String> names = new ArrayList<>();
        Collections.addAll(names,"张三丰","张无忌","周芷若","赵强","张强");
        //2.如何获取Set集合的Stream流
        Set<String> set = new HashSet<>();
        Collections.addAll(set,"刘德华","张曼玉","蜘蛛精","马德","德玛西亚");
        //3.如何获取Map集合的Stream流
        Map<String, Double> map = new HashMap<>();
        map.put("古力娜扎",172.3);
        map.put("迪丽热巴",168.3);
        map.put("马尔扎哈",166.3);
        map.put("卡尔扎巴",168.3);
        //4、如何获取数组的stream流
        String[] names2 = {"张翠山","东方不败","唐大山","独孤求败"};
        List<String> collect = Arrays.stream(names2).filter(e -> e.startsWith("东")).collect(Collectors.toList());
        System.out.println(collect);
        String[] array = Stream.of(names2).filter(e -> e.startsWith("东")).toArray(String[]::new);
        System.out.println("===>"+ Arrays.toString(array));
    }
}
